package com.yyaccp.appinfo.utils;

import com.yyaccp.appinfo.domain.AppInfo;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;

import java.io.File;
import java.io.FileOutputStream;
import java.util.List;

public class ExcelUtils {

    public static void export(List<AppInfo> list) throws  Exception {
        Workbook wb = new HSSFWorkbook();
        File file = new File("d:\\Demo");
        if(!file.exists()){
            file.mkdirs();
        }
        FileOutputStream fout = new FileOutputStream("d:\\Demo\\poi.xls");

        Sheet sheet = wb.createSheet("第一个sheet页");
       for(int i = 0;i<list.size();i++){
           AppInfo appInfo = list.get(i);
           Row row = sheet.createRow(i);       //创建一个行
           int j = 0;
           row.createCell(j++).setCellValue(appInfo.getId());
           row.createCell(j++).setCellValue(appInfo.getSoftwareName());
           row.createCell(j++).setCellValue(appInfo.getAPKName());
           row.createCell(j++).setCellValue(appInfo.getAppInfo());
           row.createCell(j++).setCellValue(appInfo.getCreationDate());
           row.createCell(j++).setCellValue(appInfo.getStatus());
       }
       wb.write(fout);
       fout.close();
    }
}
